#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
unordered_map<int, unordered_map<int, int>> h;
int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        string x, y;
        cin >> x >> y;
        int l = (x[0] - 'A') * 131 + (x[1] - 'A');
        int r = (y[0] - 'A') * 131 + (y[1] - 'A');
        if(l != r) {
            ans += h[r][l];
        }
        h[l][r]++;
    }
    cout << ans << endl;
    return 0;
}